package cn.com.pc.content.dto;

import cn.com.pc.content.domain.Biz;
import cn.com.pc.content.domain.content.ContentType;
import cn.com.pc.content.domain.Site;
import cn.com.pc.content.domain.metadata.ContentProperty;
import cn.com.pc.content.domain.metadata.ContentDataType;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import lombok.ToString;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.NotNull;
import java.time.LocalDateTime;

@Data
@ToString
public class ContentPropertyDTO {
    private Long id;
    @NotNull(message = "name不能为空")
    private String name;
    private Site site;
    private Biz biz;
    @NotNull(message = "contentType不能为空")
    private ContentType contentType;
    @NotNull(message = "dataType不能为空")
    private ContentDataType dataType;
    @NotNull(message = "hasIndex不能为空")
    private Boolean hasIndex;
    @NotNull(message = "needAudit不能为空")
    private Boolean needAudit;
    @JsonFormat(timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    private LocalDateTime createdAt;
    private String createdBy;

    public static ContentPropertyDTO from(ContentProperty contentProperty) {
        ContentPropertyDTO contentPropertyDTO = new ContentPropertyDTO();
        BeanUtils.copyProperties(contentProperty, contentPropertyDTO);
        return contentPropertyDTO;
    }
}
